package com.hq.door.dto;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.hq.door.pojo.TParent;
import com.hq.door.util.ExcelUtil;

/**
 * 后端
 *		家长管理信息
 * 作者：袁健宝
 * 日期：2017年1月4日 上午8:49:30
 */
public class ParentInfoBack {
	
	//家长信息
	private Integer id;			//家长id，主键
	private String parentName;	//家长姓名
	private String code;		//家长编号
	private String mobile;		//家长手机号
	private String address;		//家庭住址
	private String relation;	//关系(父子、父女、母子、母女)
	//关联学生信息(孩子)
	private String stuCode;		//学号
	private String stuName;		//学生(孩子)姓名
	//系统信息
	private Integer modifyBy=0;	//修改人
	private Date modifyTime;	//修改时间
	private String password;	//修改密码
	@Override
	public String toString() {
		return "ParentInfoBack [id=" + id + ", parentName=" + parentName
				+ ", code=" + code + ", mobile=" + mobile + ", password=" + " address="
				+ address + ", relation=" + relation + ", stuCode=" + stuCode
				+ ", stuName=" + stuName + "]";
	}

	public ParentInfoBack(){}
	
	public ParentInfoBack(String parentName, String mobile,
			String address, String relation, String stuCode, String stuName, String password) {
		this.parentName = parentName;
		this.mobile = mobile;
		this.address = address;
		this.relation = relation;
		this.stuCode = ExcelUtil.str2Int(stuCode)+"";
		this.stuName = stuName;
		this.password = password;
	}
	
	public ParentInfoBack(Integer id, String parentName, String mobile,
			String address, String relation, String stuCode, String stuName, String password) {
		this.id = id;
		this.parentName = parentName;
		this.mobile = mobile;
		this.address = address;
		this.relation = relation;
		this.stuCode = ExcelUtil.str2Int(stuCode)+"";
		this.stuName = stuName;
		this.password = password;
	}
	
	/**
	 * 数据库对象 pojo转换成自定义家长类
	 * @param parent	
	 * @return
	 */
	public static ParentInfoBack writeParent(TParent tparent){
		ParentInfoBack pib = null;
	    if (tparent != null){
	    	pib = new ParentInfoBack();
	    	pib.setId(tparent.getId());	//id
	    	pib.setParentName(tparent.getName());		//家长姓名
	    	pib.setMobile(tparent.getCode());			//家长编号
	    	pib.setPassword(tparent.getPassword());		//家长密码
	    	pib.setAddress("");			//家庭住址
	    	pib.setRelation("");		//与学生关系
	    	if(tparent.getTStudent()!=null){
	    		pib.setStuCode(tparent.getTStudent().getCode());			//学号
		    	pib.setStuName(tparent.getTStudent().getName());			//学生姓名
	    	}
	    }
	    return pib;
    }
	/**
	 * 查询多条家长信息
	 * @param tparents
	 * @return
	 */
	public static List<ParentInfoBack> writeParent(List<TParent> tparents){
		List<ParentInfoBack> pibs = new ArrayList<ParentInfoBack>();
		for (TParent tparent : tparents) {
			ParentInfoBack pib = writeParent(tparent);
			pibs.add(pib);
		}
		return pibs;
	}
	
	/**
	 * 转换成数据库对象 pojo
	 * @param parent	
	 * @return
	 */
	public static TParent readParent(ParentInfoBack pib){
		TParent tparent = null;
		if (pib != null){
			tparent = new TParent();
			tparent.setId(pib.getId());
			tparent.setName(pib.getParentName());
			tparent.setCode(pib.getMobile());
			tparent.setPassword(pib.getPassword());		//修改密码测试数据
			tparent.setModifiedTime(new Timestamp((new Date()).getTime()));
			tparent.setModifiedBy(pib.getModifyBy());//
		}
		return tparent;
	}
	/**
	 * 转换数据为数据库对象
	 * @param tparents
	 * @return
	 */
	public static List<TParent> readParent(List<ParentInfoBack> pibs){
		List<TParent> tparents = new ArrayList<TParent>();
		for (ParentInfoBack pib : pibs) {
			TParent parent = readParent(pib);
			tparents.add(parent);
		}
		return tparents;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getParentName() {
		return parentName;
	}

	public void setParentName(String parentName) {
		this.parentName = parentName;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getRelation() {
		return relation;
	}

	public void setRelation(String relation) {
		this.relation = relation;
	}

	public String getStuCode() {
		return stuCode;
	}

	public void setStuCode(String stuCode) {
		this.stuCode = stuCode;
	}

	public String getStuName() {
		return stuName;
	}

	public void setStuName(String stuName) {
		this.stuName = stuName;
	}

	public Integer getModifyBy() {
		return modifyBy;
	}

	public void setModifyBy(Integer modifyBy) {
		this.modifyBy = modifyBy;
	}

	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
